package group2.controller;

import group2.model.UserInfo;
import group2.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 周祖航
 * @date 2020/8/18 001823:12
 **/
@Controller
@RequestMapping("/user")
public class UserController {

    static Logger logger = Logger.getLogger(UserController.class);
    @Autowired
    UserService userService;


    /*
     * 显示所有用户
     * */
    @RequestMapping("/selectUserAll")
    public String search(HttpSession session){

        List<UserInfo> userList = this.userService.userForSelectAll();

        session.setAttribute("userList",userList);

        return "redirect:/views/menber-list.jsp";
    }
    /*
    * 用户删除
    *
    * */
    @RequestMapping("/deleteUser")
    public String deleteUserById(int Id){
        userService.userForDelete(Id);
        return "redirect:/user/selectUserAll";
    }
    /*
    * 添加用户
    * */
    @RequestMapping("/addUser")
    public String addUser(UserInfo userInfo){
        this.userService.userForAdd(userInfo);
        return  "redirect:/views/success.jsp";
    }
    /*
    * 修改用户
    * */
    @RequestMapping("/userEdit")
    public String userEdit(UserInfo user){
        this.userService.userForUpdate(user);
        return  "redirect:/views/success.jsp";
    }

}
